<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import firstLegTransportation from '@/api/document/firstLegTransportation'
import dictHelp from "@/utils/dicthelp.js";

const crudRef = ref()


const options = reactive({
  id: 'first_leg_transportation',
  pageLayout: 'fixed',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: firstLegTransportation.getList,
  recycleApi: firstLegTransportation.getRecycleList,
  add: {
    show: true,
    api: firstLegTransportation.save,
    auth: ['document:firstLegTransportation:save']
  },
  edit: {
    show: true,
    api: firstLegTransportation.update,
    auth: ['document:firstLegTransportation:update']
  },
  delete: {
    show: true,
    api: firstLegTransportation.deletes,
    auth: ['document:firstLegTransportation:delete'],
    realApi: firstLegTransportation.realDeletes,
    realAuth: ['document:firstLegTransportation:realDeletes']
  },
  recovery: {
    show: true,
    api: firstLegTransportation.recoverys,
    auth: ['document:firstLegTransportation:recovery']
  },
  tabs: {
    dataIndex: "type",
    searchKey: "type",
  }
})

const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "类型",
    dataIndex: "type",
    formType: "radio",
    type: 'button',
    search: true,
    commonRules: {
      required: true,
      message: "请输入类型"
    },
    dict: {name: "flrstLegType", translation: true},
    onChange: (value, maFormObject) => {
      let formData = maFormObject.formModel.value
      delete formData.departure
      delete formData.destination
      let dict = maFormObject.getColumnService().dicts
      // 提单类型切换
      let columnService = maFormObject.getColumnService()
      columnService.get('departure').setAttr('display', true)
      columnService.get('destination').setAttr('display', true)
      // 切换出发地,目的地
      columnService.getDictService('departure').loadDict(dictHelp.place_with_type(value), dict)
      columnService.getDictService('destination').loadDict(dictHelp.place_with_type(value), dict)
    }
  },
  {
    title: "名称",
    dataIndex: "name",
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入名称"
    }
  },
  {
    title: "出发地",
    dataIndex: "departure",
    formType: "select",
    addDisplay: false,
    search: true,
    dict: dictHelp.place,
    commonRules: {
      required: true,
      message: "请输入出发地"
    }
  },
  {
    title: "目的地",
    dataIndex: "destination",
    formType: "select",
    search: true,
    addDisplay: false,
    dict: dictHelp.place,
    commonRules: {
      required: true,
      message: "请输入目的地"
    }
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "更新者",
    dataIndex: "updated_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>
<script> export default {name: 'document:firstLegTransportation'} </script>